﻿using System.Linq;
using Microsoft.EnterpriseManagement.Common;
using Microsoft.EnterpriseManagement.Configuration;

namespace System.ServiceManager.Facade
{

    public abstract class SCSMClass
    {
        
    }

    public  class SCSMIncident : SCSMClass
    {

        
        //public static EnterpriseManagementObjectProjection CreateIncident()
        //{
        //    return new EnterpriseManagementObjectProjection(SCSMServer.CurrentManagementGroup, IncidentClass);
        //}

        public static EnterpriseManagementObjectProjection GetIncident(string id)
        {

            var builder = new CriteriaBuilder();
            builder.AddReferences("System.WorkItem.Incident.Library", "IncidentMP");

            var property = "$Target/Property[Type='IncidentMP!System.WorkItem.Incident']/Id$";

            var criteria = builder.CreateSimpleCriteria(SCSMServer.GetTypeProjection("285cb0a2-f276-bccb-563e-bb721df7cdec"), property, id);

            return SCSMServer.GetObjectProjectionReader(criteria, ObjectQueryOptions.Default).FirstOrDefault();
        }

        public static EnterpriseManagementObject GetIncidentObject(string id)
        {

            return SCSMServer.GetObject<EnterpriseManagementObject>(id);
        }

    }
}
